// component_demo/scroll-view/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getAllTabPosition(res=>{
      const allWeight=res[0][res[0].length-1].right
      this.setData({
        allWeight:allWeight,
        barWeight:375/allWeight*100
      })
    })

  },
  
  onScroll(e){
      this.setBar(e)
  },
  binddragend(e){
    console.log('结束');
    this.setBar(e)
  },
  setBar(e){
    const left=e.detail.scrollLeft;  
    const leftB=left/(this.data.allWeight-375)*100
    const barAllLeft=100-this.data.barWeight;
    this.setData({
      barLeft:barAllLeft/100*leftB
    })
  },
  getAllWidth(){
    const query = wx.createSelectorQuery()
          query.select('#the-id').boundingClientRect()
          query.exec(function(res){
          })
  },
  getAllTabPosition(callback){
      const query = wx.createSelectorQuery().in(this)
        query.selectAll('.item').boundingClientRect()
        query.selectViewport()
        query.exec((res) => {
          callback(res)
        })
    },
})